﻿package mortal.game.view.task.data
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import extend.language.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.gLinkText.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.proxy.*;
    import mortal.mvc.core.*;

    public class TaskInfo extends Object
    {
        public var stask:STask;
        public var playerTask:SPlayerTask;
        private var _totalStep:int = -1;
        private var _status:int = 0;
        public var maxStatus:int = -1;
        public var lastStep:int = -1;

        public function TaskInfo()
        {
            return;
        }// end function

        public function get status() : int
        {
            return this._status;
        }// end function

        public function set status(param1:int) : void
        {
            this._status = param1;
            this.maxStatus = Math.max(param1, this.maxStatus);
            return;
        }// end function

        public function get curStep() : int
        {
            if (this.isCanget())
            {
                return 0;
            }
            if (this.isComplete() || this.isFail())
            {
                return (this.totalStep - 1);
            }
            return this.playerTask.currentStep;
        }// end function

        public function getCurLinkData() : GLinkTextData
        {
            var _loc_1:* = Cache.instance.task.getLinkTextData(this.stask.code);
            if (_loc_1 == null || _loc_1[this.curStep] == null)
            {
                return null;
            }
            var _loc_2:* = _loc_1[this.curStep][0] as GLinkTextData;
            return _loc_2;
        }// end function

        public function get totalStep() : int
        {
            var _loc_1:Dictionary = null;
            var _loc_2:Array = null;
            if (this._totalStep < 0)
            {
                _loc_1 = this.stask.processMap;
                this._totalStep = 2;
                for each (_loc_2 in _loc_1)
                {
                    
                    var _loc_5:String = this;
                    var _loc_6:* = this._totalStep + 1;
                    _loc_5._totalStep = _loc_6;
                }
            }
            return this._totalStep;
        }// end function

        public function getTargetX(param1:int, param2:int = 0) : int
        {
            var _loc_3:* = this.stask.processMap[param1];
            if (_loc_3 == null)
            {
                return 0;
            }
            var _loc_4:* = _loc_3[param2];
            if (_loc_4 == null)
            {
                return 0;
            }
            var _loc_5:* = _loc_4.contents.length;
            return int(_loc_4.contents[_loc_5 - 2]);
        }// end function

        public function getTargetY(param1:int, param2:int = 0) : int
        {
            var _loc_3:* = this.stask.processMap[param1];
            if (_loc_3 == null)
            {
                return 0;
            }
            var _loc_4:* = _loc_3[param2];
            if (_loc_4 == null)
            {
                return 0;
            }
            var _loc_5:* = _loc_4.contents.length;
            return int(_loc_4.contents[(_loc_5 - 1)]);
        }// end function

        public function isCanget() : Boolean
        {
            return this.status == ETaskStatus._ETaskStatusCanGet;
        }// end function

        public function isDoing() : Boolean
        {
            return this.status == ETaskStatus._ETaskStatusNotComplete;
        }// end function

        public function isComplete() : Boolean
        {
            return this.status == ETaskStatus._ETaskStatusHadComplete || this.isCanNotEnd();
        }// end function

        public function isCanNotEnd() : Boolean
        {
            return this.status == ETaskStatus._ETaskStatusCantEnd;
        }// end function

        public function isCompleted() : Boolean
        {
            return this.status == ETaskStatus._ETaskStatusHadEnd;
        }// end function

        public function isFail() : Boolean
        {
            return this.status == ETaskStatus._ETaskStatusHadFail;
        }// end function

        public function isTimeLimitTask() : Boolean
        {
            var _loc_2:SConditon = null;
            var _loc_1:* = this.stask.completeConditions;
            if (_loc_1 == null || _loc_1.length == 0)
            {
                return false;
            }
            for each (_loc_2 in _loc_1)
            {
                
                if (_loc_2.type == ETaskCompleteCondition._ETaskCompleteConditionTime)
                {
                    return true;
                }
            }
            return false;
        }// end function

        public function update(param1:SPlayerTaskUpdate) : void
        {
            var _loc_2:Boolean = false;
            if (this.stask.group == ETaskGroup._ETaskGroupGuild && this.playerTask.extend != EColor._EColorOrange && param1.extend == EColor._EColorOrange)
            {
                _loc_2 = true;
                if (FrameManager.flashFrame.getTime() - TaskProxy.clickShareTime <= 5000)
                {
                    this.playerTask.canShare = false;
                }
                else
                {
                    this.playerTask.canShare = true;
                }
            }
            this.lastStep = this.playerTask.currentStep;
            this.playerTask.currentStep = param1.currentSetp;
            this.playerTask.status = param1.status;
            this.playerTask.stepRecords = param1.stepRecords;
            this.playerTask.extend = param1.extend;
            this.status = param1.status;
            if (_loc_2)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TaskGuildGot, this.playerTask));
            }
            return;
        }// end function

        public function getName(param1:Boolean = true, param2:Boolean = false) : String
        {
            var _loc_4:String = null;
            var _loc_5:int = 0;
            var _loc_3:String = "";
            if (this.stask == null)
            {
                return _loc_3;
            }
            _loc_3 = this.stask.name;
            if (param2)
            {
                _loc_3 = "<font color=\'#FF73AB\'>[" + TaskRule.getGroupShortName(this.stask.group) + "]</font>" + _loc_3;
            }
            if (param1)
            {
                _loc_4 = GlobalStyle.colorChen;
                _loc_5 = 20157;
                if (this.isCanget())
                {
                    _loc_5 = 20158;
                    _loc_4 = GlobalStyle.colorLv;
                }
                else if (this.isDoing())
                {
                    _loc_4 = GlobalStyle.colorHuang;
                    _loc_5 = 20156;
                }
                _loc_3 = _loc_3 + ("<font color=\'" + _loc_4 + "\'>(" + Language.getString(_loc_5) + ")</font>");
            }
            return _loc_3;
        }// end function

        public function getTypeName() : String
        {
            switch(this.stask.group)
            {
                case ETaskGroup._ETaskGroupMain:
                {
                    return Language.getStringByParam(21160, Language.getString(21155));
                }
                case ETaskGroup._ETaskGroupBranch:
                {
                    return Language.getStringByParam(21160, Language.getString(21156));
                }
                case ETaskGroup._ETaskGroupAutoFight:
                case ETaskGroup._ETaskGroupLoop:
                case ETaskGroup._ETaskGroupEscort:
                {
                    return Language.getStringByParam(21160, Language.getString(21157));
                }
                case ETaskGroup._ETaskGroupGuild:
                {
                    return Language.getStringByParam(21160, Language.getString(21158));
                }
                case ETaskGroup._ETaskGroupMinning:
                {
                    return Language.getStringByParam(21160, Language.getString(21159));
                }
                case ETaskGroup._ETaskGroupSpy:
                case ETaskGroup._ETaskGroupPvp:
                {
                    return Language.getStringByParam(21160, Language.getString(21561));
                }
                default:
                {
                    break;
                }
            }
            return "";
        }// end function

        public function getStatusName(param1:Boolean = true) : String
        {
            var _loc_2:String = "";
            var _loc_3:String = "#ffff00";
            var _loc_4:int = 20157;
            if (this.isCanget())
            {
                _loc_4 = 20158;
                _loc_3 = "#00ff00";
            }
            else if (this.isDoing())
            {
                _loc_3 = "#00ff00";
                _loc_4 = 20156;
            }
            else if (this.isFail())
            {
                _loc_3 = "#ff0000";
                _loc_4 = 20170;
            }
            if (param1)
            {
                _loc_2 = _loc_2 + ("<font color=\'" + _loc_3 + "\'>(" + Language.getString(_loc_4) + ")</font>");
            }
            else
            {
                _loc_2 = _loc_2 + ("(" + Language.getString(_loc_4) + ")");
            }
            return _loc_2;
        }// end function

        public function get isNotAutoPath() : Boolean
        {
            if (this.stask == null)
            {
                return false;
            }
            if ((this.stask.guide & 2) == 2)
            {
                return true;
            }
            return false;
        }// end function

        public function get isCanQuickFinish() : Boolean
        {
            if (this.stask == null)
            {
                return false;
            }
            return (this.stask.canQuickComplete & ETaskQuick._ETaskQuickFinish) > 0;
        }// end function

        public function get isCanQuickComplete() : Boolean
        {
            if (this.stask == null)
            {
                return false;
            }
            return (this.stask.canQuickComplete & ETaskQuick._ETaskQuickComplete) > 0;
        }// end function

    }
}
